/**
 * @ignore
 */
Ext.apply(NG.views, {
	
	/**
	 * Creates GeoLocate control.
	 * 
	 * @param mapView
	 * @param vector
	 * @returns {OpenLayers.Control.Geolocate}
	 */
	createGeolocateControl: function (mapView, vector) {

		var geolocate = new OpenLayers.Control.Geolocate({
	        id: 'locate-control',
	        geolocationOptions: {
	            enableHighAccuracy: false,
	            maximumAge: 0,
	            timeout: 7000
	        }
	    });
		
		var style = {
	        fillOpacity: 0.1,
	        fillColor: '#000',
	        strokeColor: '#f00',
	        strokeOpacity: 0.6
		};
	    geolocate.events.register("locationupdated", this, function(e) {
	    	NGLogger.info('locationupdated');
	        vector.removeAllFeatures();
	        alert(e.point.x + " - " + e.point.y);
	        vector.addFeatures([
	            new OpenLayers.Feature.Vector(
	                e.point,
	                {},
	                {
	                    graphicName: 'cross',
	                    strokeColor: '#f00',
	                    strokeWidth: 2,
	                    fillOpacity: 0,
	                    pointRadius: 10
	                }
	            ),
	            new OpenLayers.Feature.Vector(
	                OpenLayers.Geometry.Polygon.createRegularPolygon(
	                    new OpenLayers.Geometry.Point(e.point.x, e.point.y),
	                    e.position.coords.accuracy / 2,
	                    50,
	                    0
	                ),
	                {},
	                style
	            )
	        ]);
	        //alert(vector.getDataExtent());
	        //mapView.map.zoomToExtent(vector.getDataExtent());
	        var lonLat = new OpenLayers.LonLat(e.point.x, e.point.y);
	        mapView.map.setCenter(lonLat, mapView.map.getZoom());
	        
	    });
		geolocate.events.register("locationfailed",this,function() {
		    NGLogger.info('Location detection failed');
		});	
		
		return geolocate;	
	},

	/**
	 * Initializes map view.
	 * 
	 * @param mapView
	 */
	initMap: function(mapView) {
		var workspace = mapView.workspace;
		if (Ext.isEmpty(workspace)) {
			alert("workspace is null");
			return;
		}
		if (mapView.map)
			mapView.map.destroy();

	    var vector = new OpenLayers.Layer.Vector("Vector Layer", {});

		var vectorPoint = new OpenLayers.Layer.Vector("Point Layer");
		var vectorPolygon = new OpenLayers.Layer.Vector("Polygon Layer");
		var vectorPath = new OpenLayers.Layer.Vector("Path Layer");
		var pointLayerControl = new OpenLayers.Control.DrawFeature(vectorPoint, OpenLayers.Handler.NGPoint, {
			mapView: mapView,
			delegator: mapView
		});
		var polygonLayerControl = new OpenLayers.Control.DrawFeature(vectorPolygon, OpenLayers.Handler.NGPolygon, {
			mapView: mapView,
			delegator: mapView
		});
		
		var pathLayerControl = new OpenLayers.Control.DrawFeature(vectorPath, OpenLayers.Handler.NGPath, {
			mapView: mapView,
			delegator: mapView
		});
		
		polygonLayerControl.events.register('activate', polygonLayerControl, function (evt) {
			mapView.endDrawingControl.activate();
			NG.util.showHint({message: (Ext.is.Android ? MSG_FINISH_DRAW_BY_DOUBLE_TAB_ANDROID : MSG_FINISH_DRAW_BY_DOUBLE_TAB)});
        });
		polygonLayerControl.events.register('deactivate', polygonLayerControl, function (evt) {
			mapView.endDrawingControl.deactivate();
        });
		
		pathLayerControl.events.register('activate', pathLayerControl, function (evt) {
			mapView.endDrawingControl.activate();
			NG.util.showHint({message: (Ext.is.Android ? MSG_FINISH_DRAW_BY_DOUBLE_TAB_ANDROID : MSG_FINISH_DRAW_BY_DOUBLE_TAB)});
        });
		pathLayerControl.events.register('deactivate', pathLayerControl, function (evt) {
			mapView.endDrawingControl.deactivate();
        });
		
		var endDrawingControl = new OpenLayers.Control.EndDrawing({mapView: mapView	});
        		
		
		var attributionControl = new OpenLayers.Control.Attribution();
		var touchNavigationControl = new OpenLayers.Control.TouchNavigation({
	        dragPanOptions: {
	            interval: 100,
	            enableKinetic: true
	        }
	    });	
		
		//Measure Controls
	    //Style the sketch fancy
	    var sketchSymbolizers = {
	        "Point": {
	            pointRadius: 4,
	            graphicName: "square",
	            fillColor: "white",
	            fillOpacity: 1,
	            strokeWidth: 1,
	            strokeOpacity: 1,
	            strokeColor: "#333333"
	        },
	        "Line": {
	            strokeWidth: 3,
	            strokeOpacity: 1,
	            strokeColor: "#666666",
	            strokeDashstyle: "dash"
	        },
	        "Polygon": {
	            strokeWidth: 2,
	            strokeOpacity: 1,
	            strokeColor: "#666666",
	            fillColor: "white",
	            fillOpacity: 0.3
	        }
	    };
	    var style = new OpenLayers.Style();
	    /*style.addRules([
	        new OpenLayers.Rule({symbolizer: sketchSymbolizers})
	    ]);*/
	    var styleMap = new OpenLayers.StyleMap({"default": style});	
	    var measureControls = {
	        line: new OpenLayers.Control.Measure(
	            OpenLayers.Handler.Path, {
	                persist: true,
	                handlerOptions: {
	                    layerOptions: {styleMap: styleMap}
	                }
	            }
	        ),
	        polygon: new OpenLayers.Control.Measure(
	            OpenLayers.Handler.Polygon, {
	                persist: true,
	                handlerOptions: {
	                    layerOptions: {styleMap: styleMap}
	                }
	            }
	        )
		};
	    for(var key in measureControls) {
	        control = measureControls[key];
	        control.events.on({
	            "measure": app.controllers.mapView.handleMeasurements,
	            "measurepartial": app.controllers.mapView.handleMeasurements
	        });
	        control.events.register('activate', control, function (evt) {
				mapView.endDrawingControl.activate();
				NG.util.showHint({message: (Ext.is.Android ? MSG_FINISH_DRAW_BY_DOUBLE_TAB_ANDROID : MSG_FINISH_DRAW_BY_DOUBLE_TAB)});
	        });
			control.events.register('deactivate', control, function (evt) {
				mapView.endDrawingControl.deactivate();
	        });	        
	    }    
	    //----
	    
		var geolocate = NG.views.createGeolocateControl(mapView, vector);
		
		var mapServer = new OpenLayers.Layer.NGMapServer("NetGis Map Server", null, {
	        transitionEffect: 'resize',
	        mapView: mapView,
	        ENABLELOCALCACHE: app.getSettings().offlineEnabled(),
	        dbName: NG_DB_NAME
		});
		
		/*
		var mapServer = new OpenLayers.Layer.OSM("OpenStreetMap", null, {
	        transitionEffect: 'resize'
	    });
		*/
		var markersLayer = new OpenLayers.Layer.Markers( "Markers" );
			
		//for easy access control
		mapView.pointLayerControl = pointLayerControl; 
		mapView.polygonLayerControl = polygonLayerControl; 
		mapView.pathLayerControl = pathLayerControl;
		mapView.touchNavigationControl = touchNavigationControl;
		mapView.measureControls = measureControls;
		mapView.endDrawingControl = endDrawingControl;
		mapView.geolocate = geolocate;
		mapView.mapServer = mapServer;
		mapView.markersLayer = markersLayer;
		mapView.vectorLayer = vector;
		
		//Openstreet Map Layer definition
		var osmLayer = new OpenLayers.Layer.OSM("OpenStreetMap", null, {
            transitionEffect: 'resize',
            isBaseLayer: false,
            visibility: false,
            units: 'm'
        });
		
		mapView.map = new OpenLayers.NGMap({
			mapView: mapView,
	        theme: null,
	        id:'map-div',
	        projection: gg, //defined in mobile-base.js
	        //units: workspace.getUnits(),
	        units: "degrees",
	        numZoomLevels: 18,
	        //tileSize: new OpenLayers.Size({w:256,h:256}),
	        //maxResolution: 8629.00836724,//156543.0339,
	        maxResolution: workspace.getMaxResolution(),
	        //minResolution: 1,
	        maxExtent: new OpenLayers.Bounds(
	        	workspace.getBoundsLeft(),
	        	workspace.getBoundsBottom(),
	        	workspace.getBoundsRight(),
	        	workspace.getBoundsTop()        	
	        ),
	        controls: [
		                pointLayerControl,
		                polygonLayerControl,
		                pathLayerControl,
		                attributionControl,
		                touchNavigationControl,
		                measureControls.line,
		                measureControls.polygon,
		                geolocate,
		                endDrawingControl
		                ],
	        layers: [
				mapServer
				,vector
				,vectorPoint
				,vectorPolygon
				,vectorPath
				,markersLayer
				,osmLayer
	        ],
	        zoom: 1
	    });
		
		endDrawingControl.activate();
		endDrawingControl.deactivate();
		
		Ext.dispatch({
			controller: app.controllers.mapView,
			action: 'doZoomControl',
			settings: app.getSettings()
		});
	},

	/**
	 * Initializes the docked items of the map view panel.
	 * @return {Array} docked items array.
	 */
	initDockedItems: function (){
		var obj = [{
				text: L_BACK,
				ui:'back',
				hidden: true, //Ext.is.Phone,
				handler:function(){
					Ext.dispatch({
						controller:app.controllers.mapView,
		                action: 'back',
		                animation: {type:'slide', direction:'right'}
					});
				}
			},{xtype: 'spacer'},
			{
				//Further release
	            iconCls: "download",
	            iconMask: true,
	            hidden: true,
	            handler: function() {
	            	if (app.views.mapView.mapServer.store)
	            		app.views.mapView.mapServer.store.cacheAreaViewed();
	            	else 
	            		Ext.Msg.alert('Uyarı', 'Harita için veritabanı yaratılmadı.', Ext.emptyFn);
	            }
	        },
			{
	            iconCls: "layers",
	            iconMask: true,
	            handler: function() {
	            	Ext.dispatch({
	            		controller: app.controllers.mapView,
	            		action: 'wmsLayers'
	            	});
	            }
	        },
			{
	            iconCls: "locate",
	            iconMask: true,
	            handler: function() {
					Ext.dispatch({
						controller:app.controllers.mapView,
		                action: 'locate'
					});            	
	            }
	        },
			{
	            iconCls: "compose",
	            handler: function() {
	            	Ext.dispatch({
	        			controller:app.controllers.mapView,
	                    action: 'putInfo',
	                    map: app.views.mapView.map,
	                    workspace: app.views.mapView.workspace
	        		});                
	            }
	        },	
	        //zoom controllers
	        /*
			{
	            iconCls: "refresh",
	            handler: function() {
	            	Ext.dispatch({
	        			controller:app.controllers.mapView,
	                    action: 'refresh',
	                    map: app.views.mapView.map,
	                    workspace: app.views.mapView.workspace
	        		});                }
	        }, {
	            iconCls: "add",
	            handler: function() {
	            	Ext.dispatch({
	        			controller:app.controllers.mapView,
	                    action: 'zoomIn',
	                    map: app.views.mapView.map,
	                    workspace: app.views.mapView.workspace
	        		});                  
	            }
	        }, {
	            iconCls: "minus",
	            handler: function() {
	            	Ext.dispatch({
	        			controller:app.controllers.mapView,
	                    action: 'zoomOut',
	                    map: app.views.mapView.map,
	                    workspace: app.views.mapView.workspace
	        		});                  
	            }
	        }, 
	        */
	        {
	            iconCls: "info",
	            gbMove: false,
	            gbStillTouching: false,
	            id: 'mapview-info-button',
	            listeners: {            	
	            	afterrender: function (button){
	            		var showFADList = false;
	                	var but = Ext.get('mapview-info-button');
	            		but.addListener("touchstart", function(event){
	            			//NGLogger.info('touchstart');
	            			//gnStartTime = Number(new Date());
	            			but.gbStillTouching = true;
	            			var ti = window.setTimeout(function(e) {
	            				if (but.gbStillTouching) {
	            					window.clearTimeout(ti);
	            					showFADList = true;
	            					/*
	            					var bb = app.views.mapView.dockedItems.items[0].items.items[5];
	            					bb.fireEvent('touchend', bb);
	            					*/
	            	            	Ext.dispatch({
	            	        			controller:app.controllers.mapView,
	            	        			mapView: app.views.mapView,
	            	                    action: 'listFAD',
	            	                    workspace: app.views.mapView.workspace,
	            	                    button: button
	            	        		});            	
	            				}
	            				but.gnStartTime = 0;
	            				but.gbMove = false;
	            				but.gbStillTouching = false;
	            			}, 500, but);
	            		}, but);
	            		but.addListener('touchmove',function(event) {
	            			but.gbMove = true;
	                	}, but);
	            		but.addListener('touchend',function(event) {
	                		NGLogger.info('touchend');
	                		but.gbStillTouching = false;
	                		if (showFADList) {
	                			//TODO butonu basılmamış şekle getir
	                			but.show();
	                			showFADList = false;
	                		} else {
	                			//This is defined in InfoActionListOverlay.js file
	                			NG.views.InfoActionListOverlay({
	                        		mapView: app.views.mapView 
	                        	}).show('pop');
	                		}
	                	}, but); 
	            	}
	            }
	        },
	        {
	            iconMask: true,
	            iconCls: "layers",
	            id: 'lastbut',
	            handler: function(button, y) {
	            	Ext.dispatch({
	        			controller:app.controllers.mapView,
	        			mapView: app.views.mapView,
	                    action: 'listCategories',
	                    workspace: app.views.mapView.workspace,
	                    button: button
	        		});            	
	            }
	        }];
		return obj;
	}
	
});

/**
 * @class NG.views.MapView 
 * @extends Ext.Panel 
 * Panel on which map is drawn.
 */
NG.views.MapView = Ext.extend(Ext.Panel, {
	
	/**
     * @property touchNavigationControl
     * @type OpenLayers.Control.TouchNavigation
     */
	touchNavigationControl: null,
	
	/**
	 * @property pointLayerControl
	 * @type OpenLayers.Control.DrawFeature
	 */
	pointLayerControl: null,
	
	/**
	 * @property polygonLayerControl
	 * @type OpenLayers.Control.DrawFeature
	 */
	polygonLayerControl: null,
	
	/**
	 * @property pathLayerControl
	 * @type OpenLayers.Control.DrawFeature
	 */
	pathLayerControl:null,
	
	/**
	 * Control has two properties. These are:<br>
	 * <li> line: OpenLayers.Control.Measure
	 * <li> polygon: OpenLayers.Control.Measure
	 * 
	 * @property measureControls
	 * @type Object
	 */
	measureControls:null,
	
	/**
	 * @property geolocate
	 * @type OpenLayers.Control.Geolocate
	 */
	geolocate: null,
	
	/**
	 * @property endDrawingControl
	 * @type OpenLayers.Control.EndDrawing
	 */
	endDrawingControl: null,
	
	/**
	 * This property is mandatory field.
	 * 
	 * @property workspace
	 * @type NG.models.Workspace
	 */
	workspace: null,
	
	/**
	 * //TODO type'ın tüm yolunu yaz
	 * 
	 * @property mapServer
	 * @type NGMapServer
	 */
	mapServer: null, //NGMapServer
	
	/**
	 * 
	 */
	markersLayer: null, //MarkersLayer
	
	/**
	 * @type OpenLayers.Layer.Vector
	 */
	vectorLayer: null,
	
	/**
	 * @ignore
	 */
	sessionID: null,
	
	/**
	 * @ignore
	 */
	categoryOffFilter: "",
	
	/**
	 * @ignore
	 */
	selectedFAD: null,

	/**
	 * @ignore
	 */
	selectedCategory: null,
	
	/**
	 * @ignore
	 */
	layout:'',
	
	/**
	 * @ignore
	 */
	iconCls: 'maps',
	
	/**
	 * If no workspace is selected a hint is displayed as (select a project from project list) according to this config item.
	 * Default value is true.
	 * Set this property before activating the view panel.
	 * @cfg {Boolean} hint
	 */
	showHint: true,
	
	/**
	 * Title of the map view panel.
	 * @property title
	 * @type String
	 */
	title: L_MAP,
	
	/**
	 * OpenLayers.Map extension. This property is the core property on which map tiles are drawn.
	 * 
	 * @property map
	 * @type OpenLayers.NGMap
	 */	
	map: null,
	
	/**
	 * Default value of this property is 'nav'. Other possible values are:<br>
	 * <li>info
	 * <li>point
	 * <li>polygon
	 * <li>shortestpath
	 * <li>distancemeasure
	 * <li>areacalculate<br>
	 * These constants are defined in {@link NG.Constants} as MAD_MODE prefix.
	 * @property mode
	 * @type String 
	 */
	mode: MAP_MODE_NAV,
	
	/**
	 * @ignore
	 */
	dockedItems: [{
		xtype:'toolbar',
		id: 'ng-mapview-toolbar',
		title: L_MAP,
		ui:'light',
		defaults: {
            iconMask: true,
            disabled: true //enabled after a workspace is renderer
		},
		items:NG.views.initDockedItems()
	}],
	
	/**
	 * @ignore
	 */
	items:[{
        xtype: "component",
        scroll: false,
        monitorResize: true,
        id: "map",
        listeners: {
            render: function (){
            },
            resize: function() {
        		alert(11);
        		if (window.map) {
                    map.updateSize();
                }
            }
        }
    }],

    /**
     * @ignore
     */
	initComponent: function() {
		NG.views.MapView.superclass.initComponent.apply(this, arguments);
		this.on('activate', function(comp){
			if (this.showHint === true)
				NG.util.showHint({
					message: 'Projelerden proje seçiniz',
					duration: 3000
				});
		}, this);
	},
	
	/**
	 * 
	 * @param {Boolean} show
	 */
	setShowHint: function(show) {
		this.showHint = show;
	},
	
	/**
	 * Sets mode of the map. Modes are described in {@link mode#}.
	 * 
	 * @param {String} mode
	 */
	setMode: function (mode){
		this.mode = mode;
		if (this.touchNavigationControl) this.touchNavigationControl.deactivate();
		if (this.pointLayerControl) this.pointLayerControl.deactivate();
		if (this.polygonLayerControl) this.polygonLayerControl.deactivate();		
		if (this.pathLayerControl) this.pathLayerControl.deactivate();
		if (this.measureControls) this.measureControls.line.deactivate();
		if (this.measureControls) this.measureControls.polygon.deactivate();
		if (this.mode === MAP_MODE_NAV && this.touchNavigationControl) {
			this.touchNavigationControl.activate();
		} else if (mode === MAP_MODE_INFO_POINT && this.pointLayerControl) {
			this.pointLayerControl.activate();
		} else if (mode === MAP_MODE_INFO_POLYGON && this.polygonLayerControl) {
			this.polygonLayerControl.activate();
		} else if (mode === MAP_MODE_INFO_SHORTEST_PATH || mode === MAP_MODE_INFO_PATH && this.pathLayerControl) {
			this.pathLayerControl.activate();
		} else if (mode === MAP_MODE_INFO_DISTANCE_MEASURE && this.measureControls) {
			this.measureControls.line.activate();
		} else if (mode === MAP_MODE_INFO_AREA_CALCULATE && this.measureControls) {
			this.measureControls.polygon.activate();
		}
	},
	
	/**
	 * 
	 * @param {NG.models.Workspace} workspace
	 */
	setWorkspace: function (workspace) {
		this.workspace = workspace;
	},

	/**
	 *  
	 * @return {NG.models.Workspace} Current workspace rendered. If none workspace is selected returns null.
	 */
	getWorkspace: function () {
		return this.workspace;
	},
	
	/**
	 * Sets the categoryOffFilter property of mapServer.
	 * 
	 * @param {String} categoryOffFilter
	 */
	setCategoryOffFilter: function (categoryOffFilter){
		if (Ext.isEmpty(categoryOffFilter)) categoryOffFilter = "";
		this.mapServer.categoryOffFilter = categoryOffFilter;
	},
	
	/**
	 * Sets the selected fad.
	 * @param {String} fadName
	 */
	setSelectedFAD: function (fadName){
		this.selectedFAD = fadName;
	},
	
	/**
	 * 
	 * @return {String}
	 */
	getSelectedFAD: function (){
		return this.selectedFAD;
	},
	
	/**
	 * Selected category is used for putinfoex insert operation.
	 * @param {NG.models.Category} category
	 */
	setSelectedCategory: function (category){
		this.selectedCategory = category;
	},

	/**
	 * Category is selected from CategoryList. 
	 * Selected category is used or putinfoex insert operation.
	 * 
	 * @return {NG.model.Category} selected category, if none is selected null.
	 */
	getSelectedCategory: function (){
		return this.selectedCategory;
	},
	
	/**
	 * There are two modes, nav and info<br>
	 * Default mode is nav.<br>
	 * Mode is changed by info segmented button
	 * @return {String} nav or info, MAP_MODE_NAV, MAP_MODE_INFO etc. Constants are defined in NG.Constant.
	 */
	getMode: function (){
		return this.mode;
	},
	
	/**
	 * 
	 * @return {Ext.Toolbar} Component named as 'ng-mapview-toolbar'
	 */
	getToolbar: function (){
		return Ext.getCmp('ng-mapview-toolbar');
	},
	
	/**
	 * Info button on toolbar is changed sometimes, for example when map mode is changed.
	 * So that this accessor method is defined in order to access outside of mapview scope.
	 * 
	 * @return {Ext.Button} Component named as 'mapview-info-button'
	 */
    getInfoButton: function (){
    	return Ext.getCmp('mapview-info-button');
    },
    
    /**
     * For future use.
     * @return {Boolean}
     */
    offlineEnabled: function (){
    	return this.mapServer.params.ENABLELOCALCACHE == true;
    },

    /**
     * For future use.
     * @param {Boolean} enable
     */
    setOffline: function (enable){
    	this.mapServer.params.ENABLELOCALCACHE = enable; 
    },
    
	/**
	 * Get the coordinate of the point on device screen.
	 * It alerts the lon lat values. This is used for test.
	 * 
	 * @param evt
	 * 
	 */
	handleMapClick: function (evt) {
		var lonlat = evt.object.getLonLatFromViewPortPx(evt.xy);
       //use lonlat
       alert(lonlat);
	},
	

	
	/**
	 * Enables all the map functions(buttons)<br>
	 * Map functions start at index of panel's buttons<br>
	 * First item is back button so index is starting with 1.<br>
	 * @function enableAllFunctions
	 * 
	 */
	enableAllFunctions: function (){
		for ( var i = 1; i < this.getToolbar().items.items.length; i++) {
			var item = this.getToolbar().items.get(i);
			if (Ext.isFunction(item.enable))
				item.enable();
		}
	},
	
	/**
	 * Renders the map with new off categories.
	 * 
	 * @param {Ng.models.Workspace} workspace
	 * @param {String} categoryOffFilter
	 */
	renderWorkspace: function(workspace, categoryOffFilter) {
		this.getToolbar().setTitle(workspace.getName());
		if (Ext.isEmpty(categoryOffFilter)) categoryOffFilter = "";
		this.workspace = workspace;
		this.categoryOffFilter = categoryOffFilter;
		this.clearQueryMode();
		NG.views.initMap(this);
		this.map.render('map');
        this.map.zoomToMaxExtent({
        	restricted:true
        });
        this.enableAllFunctions();
        if (Ext.getCmp("netgis-categorylist-id")) {
        	Ext.getCmp("netgis-categorylist-id").clear();
        }
        this.setSelectedFAD(null);
        //TODO
        /* marker için ipad'de
        this.map.events.register('touchend', this.map, function (evt){
        	alert(evt);
        });*/
	},
	
	/**
	 * Renders the map with new categories.
	 * Calls <b>renderWorkspace</b> with recent workspace.
	 * @param {String} categoryOffFilter
	 */
	renderWorkspaceWithOffCategories: function(categoryOffFilter) {
		console.log("COF: " + categoryOffFilter);
		this.setCategoryOffFilter(categoryOffFilter);
		this.rerenderMap();
	},
	
	/**
	 * Rerenders map with present zoom level.<br>
	 * Openlayers zoomTo function does not any effect if the present zoom is equals to intended zoom level.<br>
	 * So that present zoom level decreased and zoomTo decreased zoom level + 1.
	 */
	rerenderMap: function () {
		this.map.zoom--;
		this.map.zoomTo(this.map.zoom + 1);
	},
	
	/**
	 * Session ID must be set before rendering the map.
	 * @param {String} sessionId
	 */
	setSessionID: function(sessionID){
		this.sessionID = sessionID; 
	},
	
	/**
	 * 
	 * @return {String}
	 */
	getSessionID: function(){
		return this.sessionID; 
	},
	
	/**
	 * Polygon drawing done callback. When polygon drawing is finished this method is called.
	 * 
	 * @param {OpenLayers.Geometry.Polygon} polygon
	 */
    polygonDone: function (polygon){
    	NGLogger.info('mapView polygon done');
    	//points forms the polygon
    	var pointArray = polygon.getVertices();
    	
    	//bounds of the polyon as rectangle
    	//var bounds = polygon.getBounds();

    	var coor =  NG.util.OpenLayerGeometryToCoordinateString(polygon);
    	
    	Ext.dispatch({
			controller:app.controllers.mapView,
			mapView: app.views.mapView,
            action: 'getInfoEx',
            workspace: app.views.mapView.workspace,
            intersects: {propertyName: 'Geometry', polygon:{coordinates:coor}}
		});
    	
    	Ext.dispatch({
    		controller:app.controllers.mapView,
    		mapVies: app.views.mapView,
    		workspace: app.views.mapView.workspace,
    		action: 'lookupXml'
    	});
    },
    
    /**
     * Point draw done collback. When point drawing is finised this method is called.
     * @param {OpenLayers.Geometry.Point} point
     */
    pointDone: function (point){
    	NGLogger.info('mapView point done');
    	var coor =  NG.util.OpenLayerGeometryToCoordinateString(point);
    	
    	Ext.dispatch({
			controller:app.controllers.mapView,
			mapView: app.views.mapView,
            action: 'getInfoEx',
            workspace: app.views.mapView.workspace,
            intersects: {propertyName: 'Geometry', point:{coordinates: coor}}
		});

    	Ext.dispatch({
    		controller:app.controllers.mapView,
    		mapVies: app.views.mapView,
    		workspace: app.views.mapView.workspace,
    		action: 'lookupXml'
    	});
        //alert(point);
    },
    
    /**
     * Path drawing done callback. When path drawing is finished this method is called.
     * 
     * @param {OpenLayers.Geometry.LineString} path
     */
    pathDone: function (path){
    	NGLogger.info('mapView path done');
    	alert(path);
    	Ext.dispatch({
    		controller: app.controllers.mapView,
    		action: 'shortestFind',
    		path: path
    	});
    },
    
    /**
     * Sets query mode of the map and badges the search button.
     * 
     * @param {NG.models.QueryMode} queryMode
     */
    setQueryMode: function (queryMode){
    	this.getInfoButton().setBadge(queryMode.getName().substring(0,1));
    	this.setMode(queryMode.getMode());
    },

    /**
     * Clears the query mode and enable map with navigation.
     * 
     */
    clearQueryMode: function (){
    	this.getInfoButton().setBadge("");
    	this.setMode(MAP_MODE_NAV);
    }
});
